home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / javax / swing / JPanel.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  5.8 KB  |  201 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)JPanel.java    1.29 98/08/28
  3.  *
  4.  * Copyright 1997, 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14. package javax.swing;
  15.  
  16. import java.awt.*;
  17.  
  18. import javax.swing.plaf.*;
  19. import javax.accessibility.*;
  20.  
  21. import java.io.Serializable;
  22. import java.io.ObjectOutputStream;
  23. import java.io.ObjectInputStream;
  24. import java.io.IOException;
  25.  
  26.  
  27. /**
  28.  * JPanel is a generic lightweight container.
  29.  * <p>
  30.  * <strong>Warning:</strong>
  31.  * Serialized objects of this class will not be compatible with 
  32.  * future Swing releases.  The current serialization support is appropriate
  33.  * for short term storage or RMI between applications running the same
  34.  * version of Swing.  A future release of Swing will provide support for
  35.  * long term persistence.
  36.  *
  37.  * @see <a href="http://java.sun.com/products/jfc/swingdoc-archive/mixing.html">
  38.  * Mixing Heavy and Light Components</a>
  39.  *
  40.  * @beaninfo
  41.  * description: A generic lightweight container.
  42.  * 
  43.  * @version 1.29 08/28/98
  44.  * @author Arnaud Weber
  45.  * @author Steve Wilson
  46.  */
  47. public class JPanel extends JComponent implements Accessible
  48. {
  49.     /**
  50.      * @see #getUIClassID
  51.      * @see #readObject
  52.      */
  53.     private static final String uiClassID = "PanelUI";
  54.  
  55.     private static final FlowLayout defaultLayout = new FlowLayout();
  56.     
  57.     /**
  58.      * Creates a new JPanel with the specified layout manager and buffering
  59.      * strategy.
  60.      *
  61.      * @param layout  the LayoutManager to use
  62.      * @param isDoubleBuffered  a boolean, true for double-buffering, which
  63.      *        uses additional memory space to achieve fast, flicker-free 
  64.      *        updates
  65.      */
  66.     public JPanel(LayoutManager layout, boolean isDoubleBuffered) {
  67.         setLayout(layout);
  68.         setDoubleBuffered(isDoubleBuffered);
  69.         setOpaque(true);
  70.         updateUI();
  71.     }
  72.  
  73.     /**
  74.      * Create a new buffered JPanel with the specified layout manager
  75.      *
  76.      * @param layout  the LayoutManager to use
  77.      */
  78.     public JPanel(LayoutManager layout) {
  79.         this(layout, true);
  80.     }
  81.  
  82.     /**
  83.      * Create a new JPanel with FlowLayout and the specified buffering
  84.      * strategy. If <code>isDoubleBuffered</code> is true, the JPanel 
  85.      * will use a double buffer.
  86.      *
  87.      * @param layout  the LayoutManager to use
  88.      * @param isDoubleBuffered  a boolean, true for double-buffering, which
  89.      *        uses additional memory space to achieve fast, flicker-free 
  90.      *        updates
  91.      */
  92.     public JPanel(boolean isDoubleBuffered) {
  93.         this(defaultLayout, isDoubleBuffered);
  94.     }
  95.  
  96.     /**
  97.      * Create a new JPanel with a double buffer and a flow layout
  98.      */
  99.     public JPanel() {
  100.         this(defaultLayout, true);
  101.     }
  102.  
  103.     /**
  104.      * Notification from the UIFactory that the L&F
  105.      * has changed. 
  106.      *
  107.      * @see JComponent#updateUI
  108.      */
  109.     public void updateUI() {
  110.         setUI((PanelUI)UIManager.getUI(this));
  111.     }
  112.  
  113.     /**
  114.      * Returns a string that specifies the name of the L&F class
  115.      * that renders this component.
  116.      *
  117.      * @return "PanelUI"
  118.      * @see JComponent#getUIClassID
  119.      * @see UIDefaults#getUI
  120.      * @beaninfo
  121.      *        expert: true
  122.      *   description: A string that specifies the name of the L&F class.
  123.      */
  124.     public String getUIClassID() {
  125.         return uiClassID;
  126.     }
  127.  
  128.  
  129.     /** 
  130.      * See readObject() and writeObject() in JComponent for more 
  131.      * information about serialization in Swing.
  132.      */
  133.     private void writeObject(ObjectOutputStream s) throws IOException {
  134.         s.defaultWriteObject();
  135.     if ((ui != null) && (getUIClassID().equals(uiClassID))) {
  136.         ui.installUI(this);
  137.     }
  138.     }
  139.  
  140.  
  141.     /**
  142.      * Returns a string representation of this JPanel. This method 
  143.      * is intended to be used only for debugging purposes, and the 
  144.      * content and format of the returned string may vary between      
  145.      * implementations. The returned string may be empty but may not 
  146.      * be <code>null</code>.
  147.      * <P>
  148.      * Overriding paramString() to provide information about the
  149.      * specific new aspects of the JFC components.
  150.      * 
  151.      * @return  a string representation of this JPanel.
  152.      */
  153.     protected String paramString() {
  154.         String defaultLayoutString = (defaultLayout != null ?
  155.                       defaultLayout.toString() : "");
  156.  
  157.     return super.paramString() +
  158.     ",defaultLayout=" + defaultLayoutString;
  159.     }
  160.  
  161. /////////////////
  162. // Accessibility support
  163. ////////////////
  164.  
  165.     /**
  166.      * Get the AccessibleContext associated with this JComponent
  167.      *
  168.      * @return the AccessibleContext of this JComponent
  169.      */
  170.     public AccessibleContext getAccessibleContext() {
  171.         if (accessibleContext == null) {
  172.             accessibleContext = new AccessibleJPanel();
  173.         }
  174.         return accessibleContext;
  175.     }
  176.  
  177.     /**
  178.      * The class used to obtain the accessible role for this object.
  179.      * <p>
  180.      * <strong>Warning:</strong>
  181.      * Serialized objects of this class will not be compatible with
  182.      * future Swing releases.  The current serialization support is appropriate
  183.      * for short term storage or RMI between applications running the same
  184.      * version of Swing.  A future release of Swing will provide support for
  185.      * long term persistence.
  186.      */
  187.     protected class AccessibleJPanel extends AccessibleJComponent {
  188.  
  189.         /**
  190.          * Get the role of this object.
  191.          *
  192.          * @return an instance of AccessibleRole describing the role of the 
  193.          * object
  194.          */
  195.         public AccessibleRole getAccessibleRole() {
  196.             return AccessibleRole.PANEL;
  197.         }
  198.     }
  199. }
  200.  
  201.